var Company = require('../model/company')
const Company_verify = require('../model/company_verify')
const axios = require('axios')
const md5 = require('md5')
var validator = require('validator');
const result = require('../utils/result')
/**
 * 企业
 * @param req
 * @param res
 * @returns {Promise<void>}
 * @constructor
 */
exports.Company = async (req,res)=>{
    Company.findAll({
        where:{
            uid:req.query.uid
        }
    }).then(v =>{
        res.json(result(0,'success',v[0]))
    })
}
/**
 * 企业认证
 * @param req
 * @param res
 * @returns {Promise<void>}
 * @constructor
 */
exports.Company_verify = async (req,res)=>{
    let uid = req.query.uid;
    if(!uid){
        res.json(result(-1,'fail','缺少参数uid'))
        return;
    };
    let p = {
        uid:req.query.uid,
        license_name:req.query.license_name,
        license_no:req.query.license_no,
        phone:req.query.phone,
        address:req.query.address,
        address_detail:req.query.address_detail,
        image:req.query.image
    }
    Company_verify.create(p).then(v =>{
        res.json(result(0,'success','认证成功'))
    }).catch(e=>{
        res.json(result(-1,'fail','认证失败'))
    })
}
/**
 * 企业信息查询
 * @param req
 * @param res
 * @returns {Promise<void>}
 * @constructor
 */
exports.Company_show= async (req,res)=>{
    let uid = req.query.uid;
    if(!uid){
        res.json(result(-1,'fail','缺少参数uid'))
        return;
    };

    Company_verify.findOne({
        where: {
            uid:uid
        }
    }).then(v =>{
        res.json(result(0,'success',v))
    }).catch(e=>{
        res.json(result(-1,'fail','认证失败'))
    })
}
